package com.ywu.app.manage.standard.api;

import com.ywu.app.manage.standard.dto.YwuAppDto;
import com.ywu.app.manage.standard.dto.YwuAppUserDto;
import com.ywu.app.manage.standard.dto.YwuOpenServiceDto;
import com.ywu.app.manage.standard.entity.YwuAppEntity;
import com.ywu.app.manage.standard.service.YwuAppService;
import com.ywu.common.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName YwuAppApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/7/29 19:30
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/app")
public class YwuAppApi {
    @Autowired
    private YwuAppService service;
    
    /**
    * @Author GroundDemo
    * @Description 分页查询
    * @Date 19:33 2024/7/29
    * @Param [ywuAppDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.query.page.list")
    public CommonResult<Object> appQueryPageList(@RequestBody YwuAppDto ywuAppDto) {
        return service.appQueryPageList(ywuAppDto);
    }

    /**
    * @Author GroundDemo
    * @Description 创建应用
    * @Date 19:34 2024/7/29
    * @Param [ywuAppDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.create.info")
    public CommonResult<Object> appCreateInfo(@RequestBody @Valid YwuAppDto ywuAppDto) {
        return service.appCreateInfo(ywuAppDto);
    }

    /**
    * @Author GroundDemo
    * @Description 修改应用信息
    * @Date 19:46 2024/7/29
    * @Param [ywuAppDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.update.info")
    public CommonResult<Object> appUpdateInfo(@RequestBody @Valid YwuAppDto ywuAppDto) {
        return service.appUpdateInfo(ywuAppDto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除应用
    * @Date 20:10 2024/7/29
    * @Param [ywuAppDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.delete.info")
    public CommonResult<Object> appDeleteInfo(@RequestBody YwuAppDto ywuAppDto) {
        return service.appDeleteInfo(ywuAppDto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询用户下的所有应用信息
    * @Date 21:04 2024/7/29
    * @Param [ywuAppUserDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.user.query.by.user.spi")
    public CommonResult<List<YwuAppEntity>> queryAppInfoByUser(@RequestBody YwuAppUserDto ywuAppUserDto) {
        return service.queryAppInfoByUser(ywuAppUserDto);
    }

    /**
    * @Author GroundDemo
    * @Description 根据应用ID查询应用信息
    * @Date 20:46 2024/8/15
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.util.List<com.ywu.app.manage.standard.entity.YwuAppEntity>>
    **/
    @PostMapping("/app.user.query.by.app.id")
    public CommonResult<List<YwuAppEntity>> queryAppInfoByAppId(@RequestBody List<YwuAppUserDto> ywuAppUserDtoList) {
        return service.queryAppInfoByAppId(ywuAppUserDtoList);
    }

    /**
    * @Author GroundDemo
    * @Description 查询当前用户下的所有应用列表&当前登录的应用
    * @Date 12:00 2024/8/3
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.user.detail.info")
    public CommonResult<Object> queryCurrentAppInfo() {
        return service.queryCurrentAppInfo();
    }

    /**
    * @Author GroundDemo
    * @Description 用户选择应用切换
    * @Date 21:54 2024/8/4
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.user.change.info")
    public CommonResult<Object> changeCurrentUserAppInfo(@RequestBody YwuAppDto ywuAppDto, HttpServletResponse response) {
        return service.changeCurrentUserAppInfo(ywuAppDto, response);
    }

    /**
     * @Author GroundDemo
     * @Description 查询所有应用
     * @Date 21:54 2024/8/4
     * @Param []
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/app.all.info")
    public CommonResult<Object> queryAllAppInfo() {
        return service.queryAllAppInfo();
    }

    /**
    * @Author GroundDemo
    * @Description appToken认证
    * @Date 11:02 2024/9/28
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/app.token.check.info.for.spi")
    public CommonResult<Object> checkAppToken(@RequestBody YwuAppDto dto) {
        return service.checkAppToken(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 获取openService的请求头token信息
    * @Date 12:03 2024/9/28
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.String>
    **/
    @PostMapping("/app.token.open.service.auth.token")
    public CommonResult<String> getOpenServiceToken(@RequestBody YwuOpenServiceDto dto) {
        return service.getOpenServiceToken(dto);
    }

}
